"ui";
var Base64 = android.util.Base64;
var Cipher = javax.crypto.Cipher;
var KeyPairGenerator = java.security.KeyPairGenerator;
var X509EncodedKeySpec = java.security.spec.X509EncodedKeySpec;
var PKCS8EncodedKeySpec = java.security.spec.PKCS8EncodedKeySpec;
var KeyFactory = java.security.KeyFactory;
var ByteArrayOutputStream = java.io.ByteArrayOutputStream;
color = "#009688";
jihuoma_version = "1085";
progressDialog = null;
jihuomaStorage = storages.create("jihuoma");
jihuoma_appId = "521";
jihuoma_pkg = "com.bhst.wu";
jihuoma_keep_check = false;
jihuoma_bindPhone = true;
huidiao = false;
os = false;
cacheCode = jihuomaStorage.get(jihuoma_appId + jihuoma_pkg + "code", "");
h = device.height
w = device.width
x = device.width;
y = device.height;
                        </horizontal>
 
                        {/* <button id="ok">确定</button> */}
 
                        <button id="ok" text="确 定" textSize="100sp" style="Widget.AppCompat.Button.Colored" h="*" w="*" />;
                    </vertical>
                    {/* </ScrollView> */}
 
                    {/* <ScrollView> */}
                    <frame>
                        <vertical bg="#B0E0E6" h="*" >;
                <Switch id="用自定义发送" text="用以下广告词发关掉此开关(打开则发3个文本话术)" textColor="blue" checked="{{相亲数据.get('用自定义发送',true)}}" padding="8 8 8 8" textSize="15sp" />
                            <viewpager id="viewpager" layout_weight="1" >
                                <vertical padding="1"  >;
                    <appbar bg="#65AF68">
                                        <tabs id="tab" bg="#65AF68" />
                                        <horizontal>
                                            <text textSize="20sp" bg="#DD2447" textColor="#FFFFFF" textStyle="bold" h="60" w="100" gravity="center" >话术切换☞</text>
                                            <spinner id="sp2" bg="#FFCC66" textSize="20sp" textColor="#FF0523" h="60" w="*" textStyle="bold" entries="适用于接视频|适用于领红包" />
                                        </horizontal>
                                        <viewpager id="viewpagers" layout_weight="1" >
                                            <vertical>
                                                <viewpager layout_weight="1" >
                                                    <ScrollView>
                                                        <frame>
                                                            <input id="主动话术" hint="输入话术" inputType="textMultiLine" textColor="white" w="*" text="{{主动话术}}" />
                                                        </frame>
                                                    </ScrollView>
                                                </viewpager>
                                                <horizontal gravity="left" bg="#4CAF50">
                                                    <button id="读取主动" text="读取默认" textSize="18sp" bg="#4CAF50" style="Widget.AppCompat.Button.Colored" marginLeft="1" marginRight="1" marginTop="1" marginBottom="1" h="auto" w={w / 3 + "px"} />;
                                    <button id="主动说明" text="帮助" textSize="18sp" bg="#4CAF50" style="Widget.AppCompat.Button.Colored" marginLeft="1" marginRight="1" marginTop="1" marginBottom="1" h="auto" w={w / 3 + "px"} />;
                                    <button id="保存主动" text="保存修改" textSize="18sp" bg="#4CAF50" style="Widget.AppCompat.Button.Colored" marginLeft="1" marginRight="1" marginTop="1" marginBottom="1" h="auto" w="*" />;
                                </horizontal>
                                            </vertical>
 
                                            <vertical>
                                                <viewpager layout_weight="1" >
                                                    <ScrollView>
                                                        <frame>
                                                            <input id="通用话术" hint="输入话术" inputType="textMultiLine" textColor="white" w="*" text="{{通用话术}}" />
                                                        </frame>
                                                    </ScrollView>
                                                </viewpager>
                                                <horizontal gravity="left" bg="#4CAF50">
                                                    <button id="读取通用" text="读取默认" textSize="18sp" bg="#4CAF50" style="Widget.AppCompat.Button.Colored" marginLeft="1" marginRight="1" marginTop="1" marginBottom="1" h="auto" w={w / 3 + "px"} />;
                                    <button id="通用说明" text="帮助" textSize="18sp" bg="#4CAF50" style="Widget.AppCompat.Button.Colored" marginLeft="1" marginRight="1" marginTop="1" marginBottom="1" h="auto" w={w / 3 + "px"} />;
                                    <button id="保存通用" text="保存修改" textSize="18sp" bg="#4CAF50" style="Widget.AppCompat.Button.Colored" marginLeft="1" marginRight="1" marginTop="1" marginBottom="1" h="auto" w="*" />;
                                </horizontal>
                                            </vertical>
 
                                            <vertical>
                                                <viewpager layout_weight="1" >
                                                    <ScrollView>
                                                        <frame>
                                                            <input id="关键词话术" hint="输入话术" inputType="textMultiLine" textColor="white" w="*" text="{{关键词话术}}" />
                                                        </frame>
                                                    </ScrollView>
                                                </viewpager>
                                                <horizontal gravity="left" bg="#4CAF50">
                                                    <button id="读取关键词" text="读取默认" textSize="18sp" bg="#4CAF50" style="Widget.AppCompat.Button.Colored" marginLeft="1" marginRight="1" marginTop="1" marginBottom="1" h="auto" w={w / 3 + "px"} />;
                                    <button id="关键词说明" text="帮助" textSize="18sp" bg="#4CAF50" style="Widget.AppCompat.Button.Colored" marginLeft="1" marginRight="1" marginTop="1" marginBottom="1" h="auto" w={w / 3 + "px"} />;
                                    <button id="保存关键词" text="保存修改" textSize="18sp" bg="#4CAF50" style="Widget.AppCompat.Button.Colored" marginLeft="1" marginRight="1" marginTop="1" marginBottom="1" h="auto" w="*" />;
                                </horizontal>
                                            </vertical>
                                        </viewpager>
                                    </appbar>
                                </vertical>
                            </viewpager>
                        </vertical>
 
                    </frame>
                    {/* </ScrollView> */}
                    <ScrollView>
                    <frame>
                        <vertical>
 
                            <horizontal gravity="left">
                                <text id="namex" text="{{namex}}" h="auto" textColor="red" textSize="20ps"></text>
                            </horizontal>
                            <horizontal gravnity="left">
                                <button id="changeName" text="添加不发的昵称" h="auto"></button>
                                <button id="initName" text="还原昵称" h="auto"></button>
                                <Switch id="不发的昵称" text="老客户" textColor="blue" checked="{{相亲数据.get('不发的昵称',false)}}" padding="8 8 8 8" textSize="15sp" />
                            </horizontal>
                        </vertical>
                    </frame>
                    </ScrollView>   
                </viewpager>
            </vertical>
            <vertical layout_gravity="left" bg="#ffffff" w="280">
            <img w="280" h="350" scaleType="fitXY" src="https://s1-i47p.5588888.xyz/e/10248/123.jpg" />
            <list id="menu">
                <horizontal bg="?selectableItemBackground" w="*">
                    <img w="50" h="50" padding="16" src="{{this.icon}}" tint="{{color}}" />
                    <text textColor="black" textSize="15sp" text="{{this.title}}" layout_gravity="center" />
                </horizontal>
            </list>
        </vertical>
 
        </drawer>
 
    );
    ui.tv_text.setSelected(true);
    ui.tv_text1.setSelected(true);
    ui.tv_text2.setSelected(true);
}
 
function getVerName(package_name) {
    let pkgs = context.getPackageManager().getInstalledPackages(0).toArray();
    for (let i in pkgs) {
        if (pkgs[i].packageName.toString() === package_name) return pkgs[i].versionName;
    }
}
 
activity.setSupportActionBar(ui.toolbar);
 
//让工具栏左上角可以打开侧拉菜单
ui.toolbar.setupWithDrawer(ui.drawer);
 
ui.menu.on("item_click", item => {
    switch (item.title) {
        case "退出":
            ui.finish();
            break;
        case "打开日志":
            app.startActivity("console");
            break;
    }
})
 
 
ui.sp2.setSelection(相亲数据.get("sp2", 0));
ui.读取主动.on("click", () => {
    相亲数据.put("sp2", ui.sp2.getSelectedItemPosition());//保存id为 sp1 的下拉框选项 到界面配置文本
    threads.start(function () {
        if (ui.sp2.getSelectedItemPosition() - 0 == 0) {
            toastLog("您的选择是:适用于接视频");
            /* var url = ab("ht",ab("tps:",ab("//","s3","-8c55"),".55"),ab("88888.","xyz","/e/"))+ab("102",ab("4","8","/"),"新")+ab("主",ab("动词","话","术"),ab(".","t","xt"));
            var res = http.get(url);
            if (res.statusCode == 200) {
                var webmod = res.body.string().replace(/--/g, "\n")
                相亲数据.put("主动话术", webmod);
            } */
			var zdhs = files.read("./新主动词话术.txt", encoding = "utf-8");
			zdhs = zdhs.replace(/--/g, "\n");
			相亲数据.put("主动话术", zdhs);
			
        } else if (ui.sp2.getSelectedItemPosition() - 0 == 1) {
            toastLog("您的选择是:适用于领红包");
            /* var url = ab("ht",ab("tps:",ab("//","s3","-8c55"),".55"),ab("88888.","xyz","/e/"))+ab("102",ab("4","8","/"),"新")+ab("主",ab("动词","话","术红包"),ab(".","t","xt"));
            var res = http.get(url);
            if (res.statusCode == 200) {
                var webmod = res.body.string().replace(/--/g, "\n")
                相亲数据.put("主动话术", webmod);
            } */
			var zdhshb = files.read("./新主动词话术红包.txt", encoding = "utf-8");
			zdhshb =zdhshb.replace(/--/g, "\n");
			相亲数据.put("主动话术", zdhshb);
        }
    });
    ui.主动话术.text(相亲数据.get("主动话术", "出现错误，请重启软件重新加载！"));
});
ui.保存主动.on("click", () => {
    相亲数据.put("自定主动话术", ui.主动话术.text())
    toastLog("主动打招呼，保存成功");
});
ui.读取通用.on("click", () => {
    相亲数据.put("sp2", ui.sp2.getSelectedItemPosition());//保存id为 sp1 的下拉框选项 到界面配置文本
    threads.start(function () {
        if (ui.sp2.getSelectedItemPosition() - 0 == 0) {
            toastLog("您的选择是:适用于接视频");
            /* var url = ab("ht",ab("tps:",ab("//","s3","-8c55"),".55"),ab("88888.","xyz","/e/"))+ab("102",ab("4","8","/"),"新")+ab("通",ab("用","词话","术"),ab(".","t","xt"));
           
            var res = http.get(url);
            if (res.statusCode == 200) {
                var webmod = res.body.string().replace(/--/g, "\n")
                相亲数据.put("通用话术", webmod);
            } */
			
			var xthchs = files.read("./新通用词话术.txt", encoding = "utf-8");
			xthchs = xthchs.replace(/--/g, "\n");
			相亲数据.put("通用话术", xthchs);
        } else if (ui.sp2.getSelectedItemPosition() - 0 == 1) {
            toastLog("您的选择是:适用于领红包");
            // var url =  ab("ht",ab("tps:",ab("//","s3","-8c55"),".55"),ab("88888.","xyz","/e/"))+ab("102",ab("4","8","/"),"新")+ab("通",ab("用词","话","术红包"),ab(".","t","xt"));
            // var res = http.get(url);
            // if (res.statusCode == 200) {
                // var webmod = res.body.string().replace(/--/g, "\n")
                // 相亲数据.put("通用话术", webmod);
            // }
			var xtyhshb = files.read("./新通用词话术红包.txt", encoding = "utf-8");
			xtyhshb = xtyhshb.replace(/--/g, "\n");
			相亲数据.put("通用话术", xtyhshb);
        }
    });
    ui.通用话术.text(相亲数据.get("通用话术", "出现错误，请重启软件重新加载！"));
});
ui.保存通用.on("click", () => {
    相亲数据.put("自定通用话术", ui.通用话术.text())
    toastLog("通用话术，保存成功");
});
ui.读取关键词.on("click", () => {
    相亲数据.put("sp2", ui.sp2.getSelectedItemPosition());//保存id为 sp1 的下拉框选项 到界面配置文本
    threads.start(function () {
        if (ui.sp2.getSelectedItemPosition() - 0 == 0) {
            toastLog("您的选择是:适用于接视频");
            /* var url = ab("ht",ab("tps:",ab("//","s3","-8c55"),".55"),ab("88888.","xyz","/e/"))+ab("102",ab("4","8","/"),"新")+ab("关",ab("键","词话","术"),ab(".","t","xt"));
            var res = http.get(url);
            if (res.statusCode == 200) {
                var webmod = res.body.string().replace(/#/g, "\n")
                相亲数据.put("关键词话术", webmod);
            } */
			
			var xgjchs = files.read("./新关键词话术.txt", encoding = "utf-8");
			xgjchs = xgjchs.replace(/#/g, "\n")
			相亲数据.put("关键词话术", xgjchs);
        } else if (ui.sp2.getSelectedItemPosition() - 0 == 1) {
            toastLog("您的选择是:适用于领红包");
            /* var url = ab("ht",ab("tps:",ab("//","s3","-8c55"),".55"),ab("88888.","xyz","/e/"))+ab("102",ab("4","8","/"),"新")+ab("关",ab("键","词话","术红包"),ab(".","t","xt"));
            var res = http.get(url);
            if (res.statusCode == 200) {
                var webmod = res.body.string().replace(/#/g, "\n")
                相亲数据.put("关键词话术", webmod);
            } */
			
			var xgjchshb = files.read("./新关键词话术红包.txt", encoding = "utf-8");
			xgjchshb = xgjchshb.replace(/#/g, "\n")
			相亲数据.put("关键词话术", xgjchshb);
        }
    });
    ui.关键词话术.text(相亲数据.get("关键词话术", "出现错误，请重启软件重新加载！"));
});
ui.保存关键词.on("click", () => {
    相亲数据.put("自定关键词话术", ui.关键词话术.text())
    toastLog("关键词话术，保存成功");
});
ui.主动说明.on("click", () => {
    alert("主动打招呼话术，每行一条信息，随机读取一行内容回复，请按此格式编辑！");
});
ui.通用说明.on("click", () => {
    alert("通用话术指根据对方的内容在关键词话术没有匹配到，然后用通用话术随机读取一行回复，每行一条信息，请按此格式编辑！");
});
ui.关键词说明.on("click", () => {
    alert("每个空行之间为一组关键词数据，每组第一个词为关键词，后面为关键词的匹配回复内容，以‘--’割开，随机读取一个回复，请按此格式编辑！");
});
function ini() {
  
    threads.start(function () {
        if (相亲数据.get("sp2", 0) == 0) {
            // toastLog("您的选择是:适用于接视频");
            /* var url = ab("ht",ab("tps:",ab("//","s3","-8c55"),".55"),ab("88888.","xyz","/e/"))+ab("102",ab("4","8","/"),"新")+ab("主",ab("动词","话","术"),ab(".","t","xt"));
            var res = http.get(url);
            if (res.statusCode == 200) {
                var webmod = res.body.string().replace(/--/g, "\n")
                相亲数据.put("主动话术", webmod);
            } */
			
			var zdchs = files.read("./新主动词话术.txt", encoding = "utf-8");
			zdchs = zdchs.replace(/--/g, "\n");
			相亲数据.put("主动话术", zdchs);
			
            // var url = ab("ht",ab("tps:",ab("//","s3","-8c55"),".55"),ab("88888.","xyz","/e/"))+ab("102",ab("4","8","/"),"新")+ab("通",ab("用","词话","术"),ab(".","t","xt"));
            // var res = http.get(url);
            // if (res.statusCode == 200) {
                // var webmod = res.body.string().replace(/--/g, "\n")
                // 相亲数据.put("通用话术", webmod);
            // }
			
			var tychs = files.read("./新通用词话术.txt", encoding = "utf-8");
			tychs = tychs.replace(/--/g, "\n");
			相亲数据.put("通用话术", tychs);
			
			
            /* var url = ab("ht",ab("tps:",ab("//","s3","-8c55"),".55"),ab("88888.","xyz","/e/"))+ab("102",ab("4","8","/"),"新")+ab("关",ab("键","词话","术"),ab(".","t","xt"));
            var res = http.get(url);
            if (res.statusCode == 200) {
                var webmod = res.body.string().replace(/#/g, "\n")
                相亲数据.put("关键词话术", webmod);
            } */
			
			var gjchs = files.read("./新关键词话术.txt", encoding = "utf-8");
			gjchs = gjchs.replace(/#/g, "\n");
			相亲数据.put("关键词话术", gjchs);
			
			
        }
    });
}
 
// threads.start(function () {
//     auto.waitFor();
//     sleep(10000);
// });
ui.不发的昵称.on("check", function (checked) {
    if (checked) {
        相亲数据.put("不发的昵称", true)
        toast("开启了，不发的昵称")
    } else {
        相亲数据.put("不发的昵称", false)
        toast("关闭了，不发的昵称")
    }
});
 
//下拉框保存界面配置
storage = storages.create("界面配置");//初始化一个可以保存界面配置的文本 ，这里的文本名称为：界面配置
function 存储数据() {
    storage.put("sp1", ui.sp1.getSelectedItemPosition());//保存id为 sp1 的下拉框选项 到界面配置文本
}
/*
如果读取下拉框sp1 在界面配置文本中不等于 undefined 则 设置下拉框sp1的选中项为 读取下拉框sp1保存的值
*/
if (storage.get("sp1") != undefined) {
    ui.sp1.setSelection(storage.get("sp1"));
};
device.keepScreenDim
//-------------
 
//老客户不发设置-------------
ui.changeName.click(() => {
    dialogs.rawInput("输入昵称,多条用|分割", ui.namex.getText(), namex => {
        ui.namex.setText(namex)
        相亲数据.put("namex",ui.namex.getText().split("|"))
        toast(相亲数据.get("namex"))
    })
});
 
ui.initName.click(function () {
    相亲数据.put("namex", ["昵称", "昵称", "昵称"])
    ui.namex.setText(相亲数据.get("namex").join("|"))
    相亲数据.put("namex",ui.namex.getText().split("|"))
    toast(相亲数据.get("namex"))
})
 
ui.emitter.on("resume", function () {
    ui.autoService.checked = auto.service != null;
});
 
ui.autoService.on("check", function (checked) {
    if (checked && auto.service == null) {
        app.startActivity({
            action: "android.settings.ACCESSIBILITY_SETTINGS"
        });
    }
    if (!checked && auto.service != null) {
        auto.service.disableSelf();
    }
});